package person.bing.fbcloud.monitor.controller;

import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import person.bing.fbcloud.common.core.util.R;
import person.bing.fbcloud.monitor.service.OrderService;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author: mengfanbing
 * @date: 2020/1/20 15:56
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private Map<String,OrderService> orderServiceMap;

    @PostMapping("/getOrder")
    public R getOrder(@RequestBody JSONObject jsonObject){
        Set<String> keySet = orderServiceMap.keySet();
        log.info("keySet={}",keySet);
        String key = jsonObject.getStr("key");
        List<Integer> moneys= jsonObject.getJSONArray("moneys").toList(Integer.class);
        log.info("key={}",key);
        log.info("moneys={}",moneys);
        return new R(orderServiceMap.get(key).calculation(moneys));
    }
}
